	$(document).ready(function (){
				    wx.config({
				        debug: false,
				        appId: $("#appid").val(),
				        timestamp: $("#timestamp").val(),
				        nonceStr: $("#nonceStr").val(),
				        signature: $("#signature").val(),
				        jsApiList: [
				            // 所有要调用的 API 都要加到这个列表中
				            'getLocation'
				        ]
				    });
				wx.ready(function(){
					wx.hideOptionMenu();
				    wx.getLocation({
				        type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
				        success: function (res) {
				            var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
				            var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
				            var center = new qq.maps.LatLng(latitude,longitude);
				            map = new qq.maps.Map(document.getElementById("map-container"), {
				                center: center,
				                zoom:15
				            });
				            marker = new qq.maps.Marker({
				                position: center,
				                map: map,
				                disableDefaultUI: true
				            })
				            findNear(center);
				            init();
				        },
				        error: function() {
				            alertWarn(false, "获取位置信息失败,请检查微信地理位置权限!")
				        }
				    });
				})
				
				
				
			function findNear(point) {
			    //alert(point);
			    geocoder = new qq.maps.Geocoder({
			        complete: function (result) {
			            curcity = result.detail.addressComponents.city;
			            var curAddress=result.detail.address;//此地点的完整路径
			            var curLatLng=result.detail.location;//此地点的经纬度
			            var html = '<li class="list-group-item" name="'+curAddress+'" address="'+curAddress+'" lat="'+curLatLng.getLat()+'" lng="'+curLatLng.getLng()+'">' +
			                '<h5 class="list-group-item-heading">'+curAddress+'</h5>' + '</li>';
			
			            var nearPoints = result.detail.nearPois;
			            for (var i = 0; i < nearPoints.length; i++) {
			                var poi = nearPoints[i];
			                var address = typeof poi.address === 'undefined' ? poi.name : poi.address;
			                html = html + '<li class="list-group-item" name="'+poi.name+'" address="'+address+'" lat="'+poi.latLng.getLat()+'" lng="'+poi.latLng.getLng()+'">' +
			                    '<h5 class="list-group-item-heading">'+poi.name+'</h5>' +
			                    '<p class="list-group-item-text text-muted"><small>'+address +
			                    '</small></p>' + '</li>';
			            }
			            $('.near-locations').scrollTop(0);
			            $('.near-locations').empty().append($(html));
			        }
			    });
			    geocoder.getAddress(point);
			}
				function init() {
					    qq.maps.event.addListener(map, 'dragend', function() {
					        centerChanged = true;
					    });
					    qq.maps.event.addListener(map, 'center_changed', function() {
					        if(centerChanged){
					            setTimeout(function(){
					                findNear(map.getCenter());
					            }, 500);
					        }
					        marker.setPosition(map.getCenter());
					        $('.navbar').hide();
					    });
					}
				var geocoder,map,marker = null;

				var HEIGHT = $('body').height();
				$(window).resize(function() {
				    $('body').height(HEIGHT);
				});


				var curcity="";
				var centerChanged=false;

				$(".loading-des").html("正在努力为您定位当前地址...");
				$("#matte").show();

				setTimeout(function(){
				    $("#matte").hide();
				},3000);

				function init() {
				    qq.maps.event.addListener(map, 'dragend', function() {
				        centerChanged = true;
				    });
				    qq.maps.event.addListener(map, 'center_changed', function() {
				        if(centerChanged){
				            setTimeout(function(){
				                findNear(map.getCenter());
				            }, 500);
				        }
				        marker.setPosition(map.getCenter());
				        $('.navbar').hide();
				    });
				}
				
					
				
				$("#search").click(function (){
				    var key = $("#key-address").val();
				    if(key){
				        search(key);
				    }
				    else{
				        alertWarn(false, "请输入要查询的地址");
				    }
				});

				$("#key-address").keypress(function(e){
				    if(e && e.keyCode==13){ // enter 键
				        $("#search").trigger("click");
				        //防止回车键提交form
				        return false;
				    }
				});
				$("#clear").click(function(){
				    $("#key-address").val("");
				})

				$('.near-locations').on('click','li',function(){
				    centerChanged = false;
				    var lat=$(this).attr("lat");
				    var lng=$(this).attr("lng");
				    var region=new qq.maps.LatLng(lat,lng);

				    $(".near-locations li span").remove();
				    if($(this).is(".active")){
				        $(this).removeClass("active");
				        $(".navbar").hide();
				    }else{
				        map.setCenter(region);
				        marker.setPosition(region);
				        $(".near-locations li").removeClass("active");
				        $(this).addClass("active");
				        $(this).html('<span class="badge glyphicon glyphicon-ok text-danger"> </span>'+$(this).html());
				        $(".navbar").show();
				    }
				});

				$('#send-client').click(function(){
				    var activeAddress = $(".near-locations li.active");
				    var lat=activeAddress.attr("lat");
				    var lng=activeAddress.attr("lng");
				    var name=activeAddress.attr("name");
				    //var address=activeAddress.attr("address");
				    if(lat && lng){
				        $.ajax({
				            type: "POST",
				            async: true,
				            data: {
				            	"lat":lat,
				            	"lng":lng,
				            	"openId":$("#openId").val(),
				            	"address":name
				            },
				            dataType: "json",
				            url: "destination/destination",
				            success: function(result){
				                if(result.code == 200){
				                    alertSuccess("发送成功",name);
				                }else if(result.code == 401){
				                    alertWarn(false, "您可能重新绑定了终端, 请重试!");
				                }else{
				                    alertWarn(false, "发送失败");
				                }
				            }
				        })
				    }else{
				        alertWarn("警告", "请先选择一个目的地");
				    }
				});

				$('#send-group').click(function(){
				    $.ajax({
				        type: "GET",
				        async: true,
				        dataType: "json",
				        url: "../../application/wx/group.php?m=groups&token="+getToken(),
				        success: function(result){
				            if(result && result.code == 401){
				                refreshToken();
				                alertWarn(false, "您可能重新绑定了终端, 请重试!");
				            }else if(result && result.data){
				                var groups = result.data;
				                $('#group-modal').modal('show');
				                var html = '';
				                if(groups && groups.length > 0){
				                    for(var i = 0; i < groups.length; i++){
				                        html = html + '<li class="list-group-item" groupId="'+groups[i]['id']+'">'+groups[i]['name']+'</li>';
				                    }
				                    $('.groups').empty().append($(html));
				                    $('.groups li').first().trigger("click");
				                }else{
				                    html = '<div class="alert alert-warning text-center" role="alert">您还没有群组</div>';
				                    $("#btn-send-group").hide();
				                    $('.groups-body').empty().append($(html));
				                }
				            }
				        }
				    })
				});

				$('#btn-send-group').click(function(){
				    var activeAddress =$(".near-locations li.active");
				    var lat=activeAddress.attr("lat");
				    var lng=activeAddress.attr("lng");
				    //var address=activeAddress.attr("address");
				    var name=activeAddress.attr("name");
				    var groupId=$(".groups li.active").attr("groupId");

				    if(groupId){
				        if(lat && lng){
				            $.ajax({
				                type: "POST",
				                async: true,
				                data: {dests:[{lat: lat, lng: lng, address: name}], groupId: groupId},
				                data: {jsondata: JSON.stringify({dests:[{lat: parseFloat(lat), lng: parseFloat(lng), address: name}], groupId: parseInt(groupId)})},
				                dataType: "json",
				                url: "../../application/wx/user.php?m=sendNavigate&token="+getToken(),
				                success: function(result){
				                    if(result.code == 200){
				                        alertSuccess("发送成功",name);
				                    }else if(result.code == 401){
				                        refreshToken();
				                        alertWarn(false, "您可能重新绑定了终端, 请重试!");
				                    }else{
				                        alertWarn(false, "发送失败");
				                    }
				                }
				            })
				        }else{
				            alertWarn("警告", "请选择目的地");
				        }
				    }else{
				        alertWarn("警告", "请选择一个群组");
				    }

				    $('#group-modal').modal('hide');
				})

				$('.groups-body ul').click('li', function(){
				    $(".groups li span").remove();
				    $(".groups li").removeClass("active");
				    $(this).addClass("active");
				    $(this).html('<span class="badge glyphicon glyphicon-ok text-danger"> </span>'+$(this).html());
				})

				function search(key){
				    var searchService = new qq.maps.SearchService({
				        complete: function(result){
				            console.log(result);
				            var html = '';
				            var pois=result.detail.pois;
				            if(pois && pois.length > 0){
				                for (var i = 0; i < pois.length; i++) {
				                    var poi = pois[i];
				                    var address = typeof poi.address === 'undefined' ? poi.name : poi.address;
				                    html = html + '<li class="list-group-item" name="'+poi.name+'" address="'+address+'" lat="'+poi.latLng.getLat()+'" lng="'+poi.latLng.getLng()+'">' +
				                        '<h5 class="list-group-item-heading">'+poi.name+'</h5>' +
				                        '<p class="list-group-item-text text-muted"><small>'+address+
				                        '</small></p>' + '</li>';
				                }
				                $('.near-locations').scrollTop(0);
				                $('.near-locations').empty().append($(html));
				                $(".near-locations li").first().trigger("click");
				            }else{
				                alertWarn(false, "没有匹配的地址");
				            }
				        },
				        error: function(){
				            alertWarn(false, "没有匹配的地址");
				        }
				    })
				    searchService.setPageIndex(0);//首页
				    searchService.setPageCapacity(20);//容量
				    searchService.setLocation(curcity);//在某个城市内搜索
				    searchService.search(key);//根据地点关键字
				};

				function alertWarn(title, content){
				    var jc = $.confirm({
				        title: title,
				        icon: 'glyphicon glyphicon-warning-sign',
				        content: content,
				        //confirmButtonClass: "btn-success",
				        confirmButton: '关闭',
				        cancelButton: false
				    })
				    jc.$content.addClass("text-center");
				    jc.$content.css({"color":"#9A3036","font-size":"16px"});
				};
				function alertSuccess(title, content){
				    var jc = $.confirm({
				        title: title,
				        icon: 'glyphicon glyphicon-ok',
				        content: content,
				        //confirmButtonClass: "btn-success",
				        confirmButton: '确定',
				        cancelButton: false
				    })
				    jc.$content.addClass("text-center");
				    jc.$content.css({"color":"#9A3036","font-size":"16px"});
				};

				function alertConfirm(title, content, process){
				    var jc = $.confirm({
				        title: title,
				        icon: 'glyphicon glyphicon-warning-sign',
				        content: content,
				        confirmButtonClass: "btn-danger",
				        cancelButtonClass: "btn-default",
				        confirmButton: '确定',
				        cancelButton: '取消',
				        confirm: process,
				        cancel: function(){
				        }
				    })
				    jc.$content.addClass("text-center");
				    jc.$content.css({"color":"#9A3036","font-size":"16px"});
				};
			})